const {
    User
} = require('../../../model/User');
const _ = require('lodash');

module.exports = async (req, res) => {
    const account = req.headers.authorization;
    if (account && account !== 'null') {
        // 查找用户
        let user = await User.findOne({
            account
        });
        // 将用户信息存储在session中
        req.session.userInfo = user;
        // 响应
        const resData = _.pick(user, ['nickname', 'account', 'role', 'avatar', '_id', 'status', 'createTime']);
        res.sendResult(resData, 200, '获取成功');
    } else {
        res.sendResult(null, 400, '获取失败');
    }
}